function selectImg(){
    galleryImg(function (path) {
        compressImage(path,'headImg',function (src) {
            upload('/api/user/upload',src,function (url) {
                $('.img').attr('style','background: url(\''+url+'\') center no-repeat;background-size:cover;');
                $('input[name=imgUrl]').val(url);
            });
        });
    });
}

function update() {
    var imgUrl = $('input[name=imgUrl]').val();
    var nickName = $('input[name=nickName]').val();
    var email = $('input[name=email]').val();
    if ($.trim(imgUrl) === ''){
        toast('头像必须上传');
        return;
    }
    if ($.trim(nickName) === ''){
        toast('昵称必须填写');
        return;
    }
    if ($.trim(email) === ''){
        toast('邮箱必须填写');
        return;
    }
    ajax({
        url: "/api/user/edit",
        type: "post",
        dataType: "json",
        headers: {
        },
        data: {nickName:nickName,email:email,imgUrl:imgUrl},
        success: function (result) {
            toast(result.data);
            evalJs("my-index",'reload()');
            closeWebview();
        },
        complete: function () {
        }
    });
}

function onPageReady() {
    var user = getLocalItem('user');
    $("body").render("#main", {});
    var $info = $(".info");
    $info.render("#img", {name:'头像',value:user.headImg || '../../../img/head.svg'});
    $info.render("#hidden", {key:'imgUrl',value:user.headImg || ''});
    $info.render("#text", {name:'昵称',key:'nickName',value:user.fullName || ''});
    $info.render("#readonly", {name:'手机',value:user.mobileNumber || ''});
    $info.render("#text", {name:'邮箱',key:'email',value:user.email || ''});
}